using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Money.Configuration;

namespace Money
{
    public partial class ConfigurationForm : Form
    {
        ApplicationConfiguration _config;

        public ConfigurationForm(ApplicationConfiguration config)
        {
            _config = config;

            InitializeComponent();

            _statementPath.Directory = _config.ImportPath;
            _saveStatementPath.Directory = _config.ImportSavePath;

            _moveOnImport.Checked = _config.MoveFileOnImport;
            _saveStatementPath.Enabled = _moveOnImport.Checked;
            _autoReconcileTransfers.Checked = _config.AutoReconcileTransfersOnImport;

            _backupInterval.Text = _config.BackupInterval.ToString();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            _config.ImportPath = _statementPath.Directory;
            _config.ImportSavePath = _saveStatementPath.Directory;
            _config.MoveFileOnImport = _moveOnImport.Checked;

            _config.AutoReconcileTransfersOnImport = _autoReconcileTransfers.Checked;

            try
            {
                _config.BackupInterval = Convert.ToInt32(_backupInterval.Text);
            }
            catch
            {
                _config.BackupInterval = 0;
            }

            DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        private void cbMoveOnImport_CheckedChanged(object sender, EventArgs e)
        {
            _saveStatementPath.Enabled = _moveOnImport.Checked;
        }
    }
}